<template>
  <el-button>one2one</el-button>
</template>

<script setup lang="ts">
import { onBeforeMount, ref } from 'vue';
import router from '../router';
import io, { Socket } from 'socket.io-client';
import { SOCKET_SERVER_URL } from '../utils/constant';

const socket = ref<Socket>();
onBeforeMount(() => {
  const { userId, roomId } = router.currentRoute.value.query;
  if (!userId || !roomId) return;

  // 连接socketio服务
  socket.value = io(SOCKET_SERVER_URL, {
    transports: ['websocket'], // 指定socketio的连接方式只为websocket，而不使用http长轮询等
    query: {
      userId,
      roomId,
    },
  });

  socket.value.on('connect', () => {
    console.log('socket-server connect success', socket.value);
  });
});
</script>
<style scoped></style>
